package com.hdsx.jxcsxm.tjbb.server.impl;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Service;
import com.hdsx.dao.query.base.BaseOperate;
import com.hdsx.jxcsxm.tjbb.bean.Bkzh;
import com.hdsx.jxcsxm.tjbb.bean.Cgsjhlr;
import com.hdsx.jxcsxm.tjbb.bean.CgsjhlrMx;
import com.hdsx.jxcsxm.tjbb.server.SbzjCgsjhServer;
import com.hdsx.jxcsxm.utile.ExcelReader;



@Service
public class SbzjCgsjhServerImpl extends BaseOperate implements SbzjCgsjhServer {
	


	public SbzjCgsjhServerImpl() {
		super("tjbb", "jdbc");
	}
	  
	 @Override 
	 public List<Cgsjhlr> autoCgsxmmc(String trim) {
		 return	  queryList("autoCgsxmmc",trim); 
		 }

	@Override
	public boolean checkcgsNameCf(Cgsjhlr cgsjhlr) {
		int i=queryOne("checkcgsNameCf",cgsjhlr);
		if (i > 0) {
			return true;
		}else {
			return false;
		}
	}

	@Override
	public List<Cgsjhlr> getsbzjCgsById(Cgsjhlr cgsjhlr) {
		return queryList("getsbzjCgsById",cgsjhlr);
	}

	@Override
	public List<Cgsjhlr> selectsbzjCgsList(Cgsjhlr cgsjhlr) {
		return queryList("selectsbzjCgsList",cgsjhlr);
	}

	@Override
	public int selectsbzjCgsListCount(Cgsjhlr cgsjhlr) {
		return queryOne("selectsbzjCgsListCount",cgsjhlr);
	}

	@Override
	public List<CgsjhlrMx> queryCgslist(CgsjhlrMx cgsjhlrMx) {
		return queryList("queryCgslist",cgsjhlrMx);
	}

	@Override
	public int queryCgslistCount(CgsjhlrMx cgsjhlrMx) {
		return queryOne("queryCgslistCount", cgsjhlrMx);
	}

	@Override
	public boolean delCgsjhlr(Cgsjhlr cgsjhlr) {
		delete("delCgsjhlr",cgsjhlr);
		delete("delCgsjhlrMxbyjhid",cgsjhlr);

		delete("delFileByParentid", cgsjhlr);
		delete("delFileRelationByXmbm", cgsjhlr);

		return true;
	}

	@Override
	public boolean delCgsjhlrMx(CgsjhlrMx cgsjhlrMx) {
		return delete("delCgsjhlrMx",cgsjhlrMx)>0;
	}


	@Override
	public boolean insertSbzjCgsjhlr(Cgsjhlr cgsjhlr,List<Map> data) {
		  Cgsjhlr x=queryOne("getsbzjCgsById", cgsjhlr); 
//			for (Map map : data) {
//				System.out.println(map);
//			}
		  if(x!=null) { 
			  //修改主表
			  //update("updateSbzjCgsjhlr", cgsjhlr); 
			  //添加子表
			  //if(!"".equals(cgsjhlr.getBcje()))
			  // insert("insertSbzjsqmx", xmjbxx);
			  // update("updateZhjhje",xmjbxx);
		  System.out.println("修改成功"); 
	  }
	  else { 
		  boolean insertBatch = insertBatch("insertSbzjCgsjhlrmx", data)==data.size();
		  if (insertBatch) {
			 insert("insertSbzjCgsjhlr", cgsjhlr);
			 return true;
		}
		  //insert("insertSbzjCgsjhlrmx", data);
		  //insertBatch("insertSbzjCgsjhlrmx", data)==data.size();
		  //System.out.println("添加项目成功");
	  } 
		  return true; 
	}

	@Override
	public Bkzh autocgshmNcgl(String xmdj) {
		return queryOne("autocgshmNcgl",xmdj);
	}

	@Override
	public Bkzh autocgshmGsd(String xmdj) {
		return queryOne("autocgshmGsd",xmdj);
	}

	@Override
	public CgsjhlrMx selectsumyeByBJID(CgsjhlrMx cgsjhlrMx) {
		return queryOne("sumyeBycgsBJID", cgsjhlrMx);
	}

	@Override
	public boolean updateSbzjcgsjhlr(Cgsjhlr cgsjhlr) {
		int update = update("updateSbzjCgsjhlr", cgsjhlr);
		return true;
	}

	@Override
	public boolean updateSbzjcgsjhlrMx(CgsjhlrMx cgsjhlrMx) {
		int update = update("updateSbzjCgsjhlrMx", cgsjhlrMx);
		return true;
	}

	@Override
	public Cgsjhlr selectsumyecgs(Cgsjhlr cgsjhlr) {
		return queryOne("selectsumyecgs",cgsjhlr);
	}

}
